
//把集合collection中相同的元素统计出数量,存入一个对象中 型如{a：{key:a,count:4}，b：{key:b,count:4}}
function count(collection,object){
  for(let item of collection){
    if(!object[item]){
      object[item] = {};
      object[item].key = item;
      object[item].count = 1;
    }
    else{
      object[item].count ++;
    }
  }
  return object;
}
function count_same_elements(collection) {
  let result = [];
  let object = {};
  count(collection,object);
  for(let item in object){
    result.push(object[item]);
  }
  return result;
}

module.exports = count_same_elements;
